#!/usr/bin/env ruby1.9
# encoding: UTF-8

require './lib/hindo.rb'

describe Tsuitta, "search" do

    it "Retries get on ssl error" do
        settings = mock "Settings"
        client = mock "Client"
        $log = mock "Log"

        settings.should_receive(:authorized?).any_number_of_times.and_return true
        settings.should_receive(:oauth_token).any_number_of_times.and_return "sdcsd"
        settings.should_receive(:oauth_token_secret).any_number_of_times.and_return "sdcsd"

        client.should_receive(:new).once.and_return client
        client.should_receive(:home_timeline).once.and_raise OpenSSL::SSL::SSLError
        client.should_receive(:home_timeline).once

        $log.should_receive(:error).once

        Tsuitta.new(settings, client).get(1)
    
    end

    it "Retries get on socket error and then throw TweetError" do
        settings = mock "Settings"
        client = mock "Client"
        $log = mock "Log"

        settings.should_receive(:authorized?).any_number_of_times.and_return true
        settings.should_receive(:oauth_token).any_number_of_times.and_return "sdcsd"
        settings.should_receive(:oauth_token_secret).any_number_of_times.and_return "sdcsd"

        client.should_receive(:new).once.and_return client
        client.should_receive(:home_timeline).twice.and_raise SocketError

        $log.should_receive(:error).once

        expect { Tsuitta.new(settings, client).get(1) }.to raise_error TweetError
    
    end

end
